using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpgradeLoaderFinger:Upgrade {

	protected override void SubscribeEvents() {
		base.SubscribeEvents();
		Mob.Death+=Mob_Death;
	}

	public override void UnsubscribeEvents() {
		base.UnsubscribeEvents();
		Mob.Death-=Mob_Death;
	}

	private void Mob_Death(object sender,DeathEventArgs e) {

		Debug.Log(e.killerWeapon.slot.weaponInstance.weaponData.name);

		if(e.killerWeapon!=weaponWeapon) return;
		if(!(weapon.owner is Humanoid)) return;
		Humanoid target = weapon.owner as Humanoid;
		if(target.weaponCount<=1) return;

		int targetSlot = -1;
		float targetCooldown = 0;
		for(int i = 0;i<target.weaponCount;i++) {
			if(!target.GetWeapon(i)||target.GetWeapon(i).weapon==null) continue;
			if(target.GetWeapon(i)==weapon) continue;
			Weapon currentWeapon = target.GetWeapon(i).weapon;
			float cdTime = currentWeapon.currentBurst.cooldownTime-currentWeapon.state.timeAfterBurst;
			if(cdTime>targetCooldown) {
				targetCooldown=cdTime;
				targetSlot=i;
			}
		}

		if(targetSlot<0) return;
		target.GetWeapon(targetSlot).weapon.state.timeAfterBurst=float.MaxValue;

	}

}
